В этой задаче Вам необходимо найти самую длинную подстроку строки \(s\), такую что каждая буква в ней встречается не менее \(k\) раз.
Если такой подстроки нет, вернуть 0.
Пример:
Вход: s = "aaabb", k = 3 Выход: 3
Объяснение: Самая длинная подходящая подстрока – "aaa", так как буква 'a' повторяется три раза. ### Описание алгоритма:
1. Генерация подстрок: Генерируем все возможные подстроки строки \(s\). Для каждой подстроки будем отслеживать частоту появления символов при помощи массива countMap.
2. Проверка валидности: Метод isValid проверяет, что каждый символ в текущей подстроке появляется хотя бы \(k\) раз. Это делается через проверку значений в массиве countMap. Если все символы удовлетворяют условию, то подстрока считается допустимой.
3. Обновление результата: Отслеживаем максимальную длину допустимых подстрок. Когда находим новую подходящую подстроку большей длины, обновляем результат. В итоге возвращаем длину самой длинной найденной подстроки. Ответ:
package main
import ( "fmt" )
func longestSubstring(s string, k int) int { if len(s) == 0 || k > len(s) { return 0 } n := len(s) result := 0
for start := 0; start < n; start++ { countMap := make([]int, 26) for end := start; end < n; end++ { countMap[s[end]-'a']++ if isValid(countMap, k) { if end-start+1 > result { result = end - start + 1 } } } } return result } func isValid(countMap []int, k int) bool { countLetters, countAtLeastK := 0, 0 for _, count := range countMap { if count > 0 { countLetters++ } if count >= k { countAtLeastK++ } } return countLetters == countAtLeastK }
В этой задаче Вам необходимо найти самую длинную подстроку строки \(s\), такую что каждая буква в ней встречается не менее \(k\) раз.
Если такой подстроки нет, вернуть 0.
Пример:
Вход: s = "aaabb", k = 3 Выход: 3
Объяснение: Самая длинная подходящая подстрока – "aaa", так как буква 'a' повторяется три раза. ### Описание алгоритма:
1. Генерация подстрок: Генерируем все возможные подстроки строки \(s\). Для каждой подстроки будем отслеживать частоту появления символов при помощи массива countMap.
2. Проверка валидности: Метод isValid проверяет, что каждый символ в текущей подстроке появляется хотя бы \(k\) раз. Это делается через проверку значений в массиве countMap. Если все символы удовлетворяют условию, то подстрока считается допустимой.
3. Обновление результата: Отслеживаем максимальную длину допустимых подстрок. Когда находим новую подходящую подстроку большей длины, обновляем результат. В итоге возвращаем длину самой длинной найденной подстроки. Ответ:
package main
import ( "fmt" )
func longestSubstring(s string, k int) int { if len(s) == 0 || k > len(s) { return 0 } n := len(s) result := 0
for start := 0; start < n; start++ { countMap := make([]int, 26) for end := start; end < n; end++ { countMap[s[end]-'a']++ if isValid(countMap, k) { if end-start+1 > result { result = end - start + 1 } } } } return result } func isValid(countMap []int, k int) bool { countLetters, countAtLeastK := 0, 0 for _, count := range countMap { if count > 0 { countLetters++ } if count >= k { countAtLeastK++ } } return countLetters == countAtLeastK }
Telegram today rolling out an update which brings with it several new features.The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations.
Export WhatsApp stickers to Telegram on iPhone
You can’t. What you can do, though, is use WhatsApp’s and Telegram’s web platforms to transfer stickers. It’s easy, but might take a while.Open WhatsApp in your browser, find a sticker you like in a chat, and right-click on it to save it as an image. The file won’t be a picture, though—it’s a webpage and will have a .webp extension. Don’t be scared, this is the way. Repeat this step to save as many stickers as you want.Then, open Telegram in your browser and go into your Saved messages chat. Just as you’d share a file with a friend, click the Share file button on the bottom left of the chat window (it looks like a dog-eared paper), and select the .webp files you downloaded. Click Open and you’ll see your stickers in your Saved messages chat. This is now your sticker depository. To use them, forward them as you would a message from one chat to the other: by clicking or long-pressing on the sticker, and then choosing Forward.